#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std;

void StartClone(int nCloneId) {
	TCHAR szFilename[MAX_PATH];
	GetModuleFileName(NULL, szFilename, MAX_PATH);
	TCHAR szCmdLine[MAX_PATH];
	wsprintf(szCmdLine, L"\"%s\"%d", szFilename, nCloneId);

	STARTUPINFO si;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	PROCESS_INFORMATION pi;

	BOOL bCreateOK = CreateProcess(szFilename, szCmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi );
	if (bCreateOK) {
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);
	}
	cout << pi.dwProcessId << endl;
}

int main(int argc, char *argv[]) {
	int nClone = 0;
	cout << "ID:" << GetCurrentProcessId()
		<< " Clone IDL" << nClone
		<< endl;
	if (argc == 2) {
		const int c_nCloneMax = 3;
		while (nClone < c_nCloneMax) {
			StartClone(++nClone);
		}
	}
	getchar();
	return 0;
}

